{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 运算符\n",
    "运算符用于执行程序代码运算，会针对一个以上操作数项目来进行运算。例如：2+3，其操作数是2和3，而运算符则是“+”。\n",
    "## Python语言支持以下类型的运算符:\n",
    "* 算术运算符\n",
    "* 比较（关系）运算符\n",
    "* 赋值运算符\n",
    "* 逻辑运算符\n",
    "* 位运算符\n",
    "* 成员运算符\n",
    "* 身份运算符\n",
    "* 运算符优先级"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 算术运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n",
      "100\n",
      "1221\n",
      "10.090909090909092\n",
      "1\n",
      "8\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "x,y,z=1,11,111\n",
    "# 加号\n",
    "print(x+y)\n",
    "# 减号\n",
    "print(z-y)\n",
    "# 乘法\n",
    "print(y*z)\n",
    "# 除法\n",
    "print(z/y)\n",
    "# 求模\n",
    "print(z % y)\n",
    "# 求幂\n",
    "print(2**3)\n",
    "# 求整除\n",
    "print(z//y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 比较运算符\n",
    "* ==：等于\n",
    "* !=：不等于\n",
    "* &gt;：大于\n",
    "* &lt;：小于\n",
    "* &gt;=：大于等于\n",
    "* &lt;=：小于等于"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "a,b,c=1,2,3\n",
    "print(a==b)\n",
    "print(a!=b)\n",
    "print(a>b)\n",
    "print(a<b)\n",
    "print(a>=a)\n",
    "print(a>=b)\n",
    "print(c>b>b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 赋值运算符\n",
    "* =\t简单的赋值运算符\n",
    "* +=\t加法赋值运算符\n",
    "* -=\t减法赋值运算符\n",
    "* *=\t乘法赋值运算符\n",
    "* /=\t除法赋值运算符\n",
    "* %=\t取模赋值运算符\n",
    "* **=\t幂赋值运算符\n",
    "* //=\t取整除赋值运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "a,b,c=1,2,3\n",
    "b//=c\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 逻辑运算符\n",
    "* and\n",
    "* or\n",
    "* not"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "x,y=False,False\n",
    "print(not x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 成员运算符\n",
    "* in\n",
    "* not in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 2 in {1,2,3}\n",
    "print('a' in ['a','b'])\n",
    "print('ac' in 'abc')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 身份运算符\n",
    "* is:is 是判断两个标识符是不是引用自一个对象\n",
    "* is not:is not 是判断两个标识符是不是引用自不同对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "a,b=1,1\n",
    "print(a is not b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 运算符优先级\n",
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "54\n"
     ]
    }
   ],
   "source": [
    "print((4+2)*3**2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
